package com.bl.weilan.api.controller.starinfo;

import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.service.biz.news.NewsService;
import com.bl.weilan.service.biz.starinfo.StarInfoService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.company.CompanyAddVo;
import com.bl.weilan.service.vo.starinfo.StarInfoListVo;
import com.bl.weilan.service.vo.tradepolicy.TradePolicyListVo;
import com.bl.weilan.service.vo.train.TrainListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/star"})
@Api(value = "收藏", description = "收藏")
public class StarInfoController extends BaseController {
    @Autowired
    StarInfoService starInfoService;

    @ApiOperation(value = "获取用户的收藏列表", notes = "获取用户的收藏列表")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<TrainListVo> getlist(
            HttpServletRequest request) {

        TrainListVo trainListVo = starInfoService.getList(getUserInfo(request).getId());

        return ApiResponseBody.createSuccessBody(trainListVo);
    }

    @ApiOperation(value = "收藏、取消", notes = "收藏 取消")
    @ApiImplicitParams({})
    @PostMapping(value = {"/collect"})
    public ApiResponseBody collect(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        starInfoService.mod(getUserInfo(request).getId(), body.getId());

        return ApiResponseBody.createSuccessBody(null);
    }

}
